package com.fool
{
	public class Opponent extends Player
	{
		private var autoRequest:Boolean = true;
		
		public function Opponent(name:String)
		{
			super(name);
		}
		
		public function decideAttack(tableCards:Array, isEndGame:Boolean):Card
		{
			var attackingList:Array = [];
			for each (var card:Card in source) 
			{
				if ( isEqualRank(tableCards, card) )
				{
					attackingList.push(card);
				}
			}
			
			if (Util.isEmpty(attackingList))
			{
				return null;
			}
			
			var result:Card = getCardWithLowestValue(attackingList);
			if ( result.isTrump  && !isEndGame )
			{
				return null;
			}
			
			return result;
		}
		
		public function desideDefending(attackingCard:Card):Card
		{
			function isStronger(element:*, index:int, arr:Array):Boolean 
			{
				var item:Card = element as Card;
				return attackingCard.compareIsStronger(item);
			}			
			
			var defendingList:Array  = source.source.filter(isStronger); 
			
			if ( !Util.isEmpty(defendingList) )
			{
				return getCardWithLowestValue(defendingList);
			}
			
			return null
		}
		

	}
}